﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MaxStudio.Concrete.DBUtility;
using MaxStudio.Concrete.Server.Dao;
using MaxStudio.Concrete.Server.Interface; 

namespace MaxStudio.Concrete.Server.Service
{
    public class RPTMixingProportionOfConcreteOrderService : ServiceHandle, IRPTMixingProportionOfConcreteOrder
    {
        #region IRPTMixingProportionOfConcreteOrder Members

        public OperationResult<List<tb_RPT_MixingProportionOfConcreteOrder>> GetAllMixingProportionOfConcreteOrder()
        {
            OperationResult<List<tb_RPT_MixingProportionOfConcreteOrder>> result = new OperationResult<List<tb_RPT_MixingProportionOfConcreteOrder>>();
            List<tb_RPT_MixingProportionOfConcreteOrder> list = new List<tb_RPT_MixingProportionOfConcreteOrder>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetAllMixingProportionOfConcreteOrder();
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_MixingProportionOfConcreteOrder>> GetMixingProportionOfConcreteOrderByContition(string strInputDate, string strProjectName, string strConstructionUnit, string strStrengthGrade, string strApproval, string strPlan)
        {
            OperationResult<List<tb_RPT_MixingProportionOfConcreteOrder>> result = new OperationResult<List<tb_RPT_MixingProportionOfConcreteOrder>>();
            List<tb_RPT_MixingProportionOfConcreteOrder> list = new List<tb_RPT_MixingProportionOfConcreteOrder>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetMixingProportionOfConcreteOrderByContition(  strInputDate,   strProjectName,   strConstructionUnit
                                                                                ,   strStrengthGrade,   strApproval,   strPlan);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_MixingProportionOfConcreteOrder> GetMixingProportionOfConcreteOrderById(int id)
        {
            ConcreteDaoDataContext dataContext = getDateContext();
            OperationResult<tb_RPT_MixingProportionOfConcreteOrder> result = new OperationResult<tb_RPT_MixingProportionOfConcreteOrder>();
            tb_RPT_MixingProportionOfConcreteOrder mixingProportionOfConcreteOrder;
            try
            {
                mixingProportionOfConcreteOrder = dataContext.GetMixingProportionOfConcreteOrderById(id);
                if (mixingProportionOfConcreteOrder == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = mixingProportionOfConcreteOrder;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_MixingProportionOfConcreteOrder> CreateMixingProportionOfConcreteOrder(tb_RPT_MixingProportionOfConcreteOrder entity)
        {
            OperationResult<tb_RPT_MixingProportionOfConcreteOrder> result = new OperationResult<tb_RPT_MixingProportionOfConcreteOrder>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.CreateMixingProportionOfConcreteOrder(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_MixingProportionOfConcreteOrder> ModifyMixingProportionOfConcreteOrder(tb_RPT_MixingProportionOfConcreteOrder entity)
        {
            OperationResult<tb_RPT_MixingProportionOfConcreteOrder> result = new OperationResult<tb_RPT_MixingProportionOfConcreteOrder>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.ModifyMixingProportionOfConcreteOrder(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_MixingProportionOfConcreteOrder> DeleteMixingProportionOfConcreteOrder(tb_RPT_MixingProportionOfConcreteOrder entity)
        {
            OperationResult<tb_RPT_MixingProportionOfConcreteOrder> result = new OperationResult<tb_RPT_MixingProportionOfConcreteOrder>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.DeleteMixingProportionOfConcreteOrder(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        #endregion
    }
}
